<?php
/*
Plugin Name: CW Easy Video Player
Plugin URI: http://www.christian-wenzl.de/wordpress-plugin-easy-video-player
Description: Easy way to display videos with the Easy Video Player (EVP)
Version: 1.0
Author: Christian Wenzl
Author URI: http://www.christian-wenzl.de
License: GPLv2
*/

load_plugin_textdomain('cw-easy-video-player', false, 'cw-easy-video-player/languages');

add_filter('the_content', 'cwevp_Contentfilter');
function cwevp_Contentfilter($content){
	$strRegex = "#_evpInit\([^a-z]+([0-9a-z]+)(={0,2})\[(evp-[a-z0-9-]+)\][^a-z]+\)#isU";
	if(!preg_match($strRegex, $content, $arrErgebnis)) return $content;
	
	$strHost = get_option('cwevp_host');
	$strTemplate = "\r\n\r\n <!-- CW Easy Video Player Plugin Begin -->\r\n";
	$strTemplate.= '<div id="\\3-wrap" class="evp-video-wrap"></div>'."\r\n";
	$strTemplate.= '<script type="text/javascript" src="'.$strHost.'/framework.php?div_id=\\3&id=\\1%3D%3D&v='.date("Ymdh").'&profile=default"></script>'."\r\n";
	$strTemplate.= '<script type="text/javascript"><!--'."\r\n";
	$strTemplate.= "_evpInit('\\1\\2[\\3]');//--></script>";
	$strTemplate.= "\r\n<!-- CW Easy Video Player Plugin End -->\r\n\r\n";

	return preg_replace($strRegex, $strTemplate, $content);
}


add_action('admin_init', 'cwevp_admin_init');
function cwevp_admin_init(){
	register_setting('media', 'cwevp_host');
	
	add_settings_section('cwevp_settings', __('Easy Video Player', 'cw-easy-video-player'), 'cwevp_settings_description', 'media');
	function cwevp_settings_description(){
		echo __('Settings for the Easy Video Player', 'cw-easy-video-player');
	}
	
	add_settings_field('cwevp_hostid', __('Host of the EVP', 'cw-easy-video-player'), 'cwevp_host_form', 'media', 'cwevp_settings');
	function cwevp_host_form(){
		$strHost = get_option('cwevp_host');
		echo "<input type='text' class='regular-text code' id='cwevp_host' name='cwevp_host' value='".esc_attr($strHost)."' /> ".__('Example:', 'cw-easy-video-player')." http://evp.christian-wenzl.de";
	}
	
}